//注册
function addUser(){
    let username= $("#username").val();
    let password= $("#psd").val();
     let obj={
         username:username,
         password:password
     }

     $.ajax({
         type:"post",
         url:"/js/addUser",
         data:JSON.stringify(obj),
         dataType:"json",
         success:function(data){
             if(data){
                 alert("添加成功")
                 location.href="./07强制登录案例---登录页面.html"
             }else{
                 alert("用户名已存在")
             }
         }

     })
 }

 //登录
 function login(){
    let username= $("#username").val();
    let password= $("#psd").val();
    let obj={
         username:username,
         password:password
     }
     //设置cookie失效时长
     let date=new Date();
     date.setTime(date.getTime()+60*1000);
     //判断用户是否选择了保持登录状态
    let checkbool= document.querySelector("#check").checked;
    if(checkbool){
         //如果用户保持了登录状态  把username保持到cookie里面并设置有效时长
         document.cookie="username="+username+";expires="+date.toUTCString();
    }else{
         document.cookie="username="+username;
    }

    

     $.ajax({
         type:"post",
         url:"/js/login",
         data:JSON.stringify(obj),
         dataType:"json",
         success:function(data){
             if(data){
                 location.href="./03茶叶/茶叶.html"
             }else{
                 alert("账号密码错误")
             }
         }
     })
 }